package beans;
// tbv Internationalisatie
import java.io.IOException;
import java.util.*;
import java.text.*;
import tools.CurrencyConverter;

public class LocalizedBean {

    private String taal;
    private Locale currentLocale;
    private ResourceBundle messages;
    private NumberFormat currencyFormatter;
    private DateFormat dateFormatter;
    private String key;

    public LocalizedBean() {
        setTaal("en");
    }
    
    public String getLanguage(){
        return taal;
    }

    public void setTaal(String s) {
        taal = s;
        currentLocale = new Locale(taal);
        messages = java.util.ResourceBundle.getBundle(taal);
        currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
        dateFormatter = DateFormat.getDateInstance(DateFormat.LONG,
                currentLocale);
        DecimalFormatSymbols decimalFormatSymbols = ((DecimalFormat) currencyFormatter).getDecimalFormatSymbols();
        decimalFormatSymbols.setCurrencySymbol("");
        ((DecimalFormat) currencyFormatter).setDecimalFormatSymbols(decimalFormatSymbols);
    }
    // Set en Get voor key

    public void setKey(String key) {
        this.key = key;
    }

    public String getKey() {
        return messages.getString(key);
    }

    public String getDate() {
        return dateFormatter.format(new Date());
    }

    public String getLocalAmount(double amount) throws IOException, ParseException {
        if( !taal.equals("nl")){
            CurrencyConverter converter = CurrencyConverter.getInstance();
            amount = converter.convert(amount, "EUR", "GBP");
        }
        
        return currencyFormatter.format(amount);
    }
}
